/**
 * Copyright (c) 2019 人人开源 All rights reserved.
 * <p>
 * https://www.yj.io
 * <p>
 * 版权所有，侵权必究！
 */

package com.commons.tools.config;

//import com.google.common.base.Function;
//import com.google.common.base.Optional;
//import com.google.common.base.Predicate;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import springfox.documentation.RequestHandler;
//import springfox.documentation.builders.ApiInfoBuilder;
//import springfox.documentation.builders.PathSelectors;
//import springfox.documentation.builders.RequestHandlerSelectors;
//import springfox.documentation.service.ApiInfo;
//import springfox.documentation.service.ApiKey;
//import springfox.documentation.spi.DocumentationType;
//import springfox.documentation.spring.web.plugins.Docket;
//import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

//import static com.google.common.collect.Lists.newArrayList;

/**
 * Swagger配置
 *
 * @author
 */
//@Configuration
//@EnableSwagger2
public class SwaggerConfig {
    /**
     * 是否开启swagger，生产环境一般关闭
     */
//    @Value("${swagger.enabled}")
    private boolean enabled ;

    // 定义分隔符
    private static final String splitor = ";";

//    @Bean
//    public Docket createRestApi() {
//        return new Docket(DocumentationType.SWAGGER_2)
//                .enable(enabled)
//                .apiInfo(apiInfo())
//                .select()
//                //加了ApiOperation注解的类，才生成接口文档
//                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
//                //包下的类，才生成接口文档
////                .apis(RequestHandlerSelectors.basePackage("com.yj.controller"))
//                //多个包下的类，生成接口文档
//                .apis(basePackage("com.yj.controller"+splitor+"com.yj.web.rest.controller"))
//                .paths(PathSelectors.any())
//                .build()
//                .directModelSubstitute(java.util.Date.class, String.class)
//                .securitySchemes(security());
//    }

//    private ApiInfo apiInfo() {
//        return new ApiInfoBuilder()
//                .title("云聚项目")
//                .description("接口文档")
//                .termsOfServiceUrl("https://www.yj.io/community")
//                .version("1.0.0")
//                .build();
//    }

    //重写扫描包方法，支持多包扫描
//    public static Predicate<RequestHandler> basePackage(final String basePackage) {
//        return input -> declaringClass(input).transform(handlerPackage(basePackage)).or(true);
//    }
//
//    private static Function<Class<?>, Boolean> handlerPackage(final String basePackage)     {
//        return input -> {
//            // 循环判断匹配
//            for (String strPackage : basePackage.split(splitor)) {
//                boolean isMatch = input.getPackage().getName().startsWith(strPackage);
//                if (isMatch) {
//                    return true;
//                }
//            }
//            return false;
//        };
//    }

//    private static Optional<? extends Class<?>> declaringClass(RequestHandler input) {
//        return Optional.fromNullable(input.declaringClass());
//    }
//    //重写扫描包方法
//
//    private List<ApiKey> security() {
//        return newArrayList(
//                new ApiKey("Authorization", "Authorization", "header"),
//                new ApiKey("IPC-TOKEN(临时)", "IPC-TOKEN", "header")
//        );
//    }
}
